<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn1">btn1</button>
    <button id="btn2">btn2</button>
    <!-- 1. 行内定义 -->
    <button onclick="demo()">btn3</button>
    <script type="text/javascript">
        function demo() {
            console.log("被点击了");
        }
        // 2. addE...调用
        document.querySelector("#btn1").addEventListener('click',()=>{
            demo()
        })
        // 3. onC...调用
        document.querySelector("#btn2").onclick = ()=>{
            demo()
        }
    </script>
</body>
</html>